package com.ninetaildemonfox.zdl.socialproject.mvp.presenter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;

import com.google.gson.JsonObject;
import com.hyphenate.easeui.utils.map.JSONUtils;
import com.ninetaildemonfox.zdl.socialproject.config.Constants;
import com.ninetaildemonfox.zdl.socialproject.http.https.Model;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.EditContract;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;

import java.io.File;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 创建人： Nine tails fox
 * 创建时间： 2019/8/10
 * 功能描述：
 * 联系方式：1037438704@qq.com
 *
 * @author NineTailDemonFox
 */

public class EditPresenter {
    private AppCompatActivity me;
    private Activity activity;
    public EditContract editContract;

    public EditPresenter(AppCompatActivity me, Activity activity, EditContract editContract) {
        this.me = me;
        this.activity = activity;
        this.editContract = editContract;
    }
    public void getModBaseDateHead(String token, String head_pic, String nickname, String birthday, final String type) {
        editContract.showLoading();
        Model.getInstance().getUserApi().getModBaseDataHead(token, head_pic, nickname, birthday, type)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null) {
                            return;
                        }
                        if (type.equals("1")) {
                            ToastUtil.show(map.get("message"));
                            activity.finish();
                        } else {
                            Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                            if (data == null) {
                                return;
                            }
                            editContract.editSucces(data);
                        }
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {

                    }
                });
    }
}
